package com.glodon.ggzy.core.utils;

import java.util.Locale;
import java.util.Map;

import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;

/**
 * 
 * 
 * MultipleViewResolver处理
 * 
 * @author yangjf
 * @since jdk1.6
 * @date 2013-6-17
 *
 */
public class MultipleViewResolver implements ViewResolver {

	private Map<String, ViewResolver> resolvers;

	public void setResolvers(Map<String, ViewResolver> resolvers) {
		this.resolvers = resolvers;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.ViewResolver#resolveViewName(java.lang
	 * .String, java.util.Locale)
	 */
	@Override
	public View resolveViewName(String viewName, Locale locale) throws Exception {
		int n = viewName.lastIndexOf(".");
		if (n == (-1))
			return null;
		String suffix = viewName.substring(n + 1);

		ViewResolver resolver = resolvers.get(suffix);
		if (resolver != null)
			return resolver.resolveViewName(viewName.substring(0, n), locale);
		return null;
	}
}
